home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / datech1r / frmmain.frm < prev    next >
Text File  |  1999-07-27  |  5KB  |  185 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form frmMain 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "NetSnake"
  6.    ClientHeight    =   5865
  7.    ClientLeft      =   3315
  8.    ClientTop       =   1455
  9.    ClientWidth     =   10725
  10.    Icon            =   "frmMain.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   5865
  14.    ScaleWidth      =   10725
  15.    Begin VB.Timer timeOut 
  16.       Enabled         =   0   'False
  17.       Interval        =   60000
  18.       Left            =   840
  19.       Top             =   1920
  20.    End
  21.    Begin MSWinsockLib.Winsock Winout 
  22.       Left            =   4800
  23.       Top             =   1680
  24.       _ExtentX        =   741
  25.       _ExtentY        =   741
  26.       _Version        =   393216
  27.    End
  28.    Begin MSWinsockLib.Winsock Winin 
  29.       Left            =   4440
  30.       Top             =   1680
  31.       _ExtentX        =   741
  32.       _ExtentY        =   741
  33.       _Version        =   393216
  34.    End
  35.    Begin VB.ListBox lstLog 
  36.       Height          =   5910
  37.       Left            =   0
  38.       TabIndex        =   0
  39.       Top             =   0
  40.       Width           =   10695
  41.    End
  42. End
  43. Attribute VB_Name = "frmMain"
  44. Attribute VB_GlobalNameSpace = False
  45. Attribute VB_Creatable = False
  46. Attribute VB_PredeclaredId = True
  47. Attribute VB_Exposed = False
  48.  
  49. Private Sub Form_Load()
  50. On Error GoTo errorHandle
  51. If Command = "" Then End
  52. App.TaskVisible = False
  53. Me.Show
  54. DoEvents
  55.  
  56. Dim newCom As String
  57.  
  58. Dim LBuffer As String * 3000
  59. Dim posCount As Long
  60.  
  61. newCom = Trim(LCase(Command))
  62. lstLog.AddItem newCom
  63.  
  64. lstLog.AddItem "mode: " & Parse(newCom, 1)
  65.  
  66. Select Case Parse(newCom, 1)
  67.     Case "in"
  68.         Winin.LocalPort = CInt(Val(Parse(newCom, 2)))
  69.         Winin.Listen
  70.         lstLog.AddItem "listening on port " & Winin.LocalPort
  71.         timeOut.Enabled = True
  72.         
  73.     Case "out"
  74.         Winout.RemoteHost = Parse(newCom, 2)
  75.         Winout.RemotePort = CInt(Val(Parse(newCom, 3)))
  76.         outFile = Parse(newCom, 4)
  77.         inFile = Parse(newCom, 5)
  78.         'check file
  79.         If Dir(outFile) = "" Then End
  80.         'end check file
  81.         Winout.Connect
  82.         lstLog.AddItem "connecting to " & Winout.RemoteHost & ":" & Winout.RemotePort
  83.         lstLog.AddItem "task: send file " & outFile & " -> " & inFile
  84.         'wait for connection
  85.         timeOut.Enabled = True
  86.         Do While Winout.State <> sckConnected: DoEvents: Loop
  87.         timeOut.Enabled = False
  88.         'start doing stuff
  89.         Winout.SendData READY
  90.         WaitFor READY
  91.         Winout.SendData IN_FILENAME & inFile
  92.         WaitFor GOT_FILENAME
  93.                 
  94.         Open outFile For Binary As #1
  95.         LBuffer = ""
  96.         Do While Not EOF(1)
  97.             fullCount = fullCount + 1
  98.             Get #1, , LBuffer
  99.             Winout.SendData IN_DATA & LBuffer
  100.             WaitFor RECEIVED
  101.             Response = ""
  102.             Me.Caption = (fullCount * 3001)
  103.             DoEvents
  104.         Loop
  105.         Close #1
  106.         Winout.SendData DONE
  107.         lstLog.AddItem "DONE"
  108.         timeOut.Enabled = True
  109.     Case Else
  110.         lstLog.AddItem "INVALID MODE"
  111.         End
  112. End Select
  113.  
  114. Exit Sub
  115. errorHandle:
  116. On Error Resume Next
  117. Open "c:\nslog.log" For Append As #2
  118.     Print #2, Err.Number & " - "; Err.Description
  119. Close #2
  120. End
  121. End Sub
  122.  
  123. Private Sub Form_Unload(Cancel As Integer)
  124. End
  125. End Sub
  126.  
  127.  
  128. Private Sub timeOut_Timer()
  129. lstLog.AddItem "TIMEOUT"
  130. End
  131. End Sub
  132.  
  133. Private Sub Winin_ConnectionRequest(ByVal requestID As Long)
  134. Winin.Close
  135. DoEvents
  136. Winin.Accept requestID
  137. End Sub
  138.  
  139. Private Sub Winin_DataArrival(ByVal bytesTotal As Long)
  140. timeOut.Enabled = False
  141. Dim cOm As String
  142. Dim writeData As String * 3001
  143.  
  144. Winin.GetData Response
  145.  
  146.  
  147. Data = Right(Response, (Len(Response) - 1))
  148. cOm = Left(Response, 1)
  149.  
  150. Select Case cOm
  151.     Case BUFFER
  152.     Case READY
  153.         Winin.SendData READY
  154.         lstLog.AddItem "SENT READY SIGNAL"
  155.     Case IN_FILENAME
  156.         inFile = Data
  157.         Winin.SendData GOT_FILENAME
  158.         lstLog.AddItem "INPUT FILE SET " & inFile
  159.     Case IN_DATA
  160.         On Error Resume Next
  161.         writeData = Data
  162.         Open inFile For Binary As #1
  163.             Seek #1, LOF(1)
  164.             Put #1, , writeData
  165.         Close #1
  166.         fullCount = fullCount + 1
  167.         Me.Caption = (fullCount * 3001): DoEvents 'log bytes received
  168.         Winin.SendData RECEIVED
  169.     Case DONE
  170.         Winin.Close
  171.         lstLog.AddItem "DONE"
  172.         timeOut.Enabled = True
  173. End Select
  174. Response = ""
  175.  
  176. timeOut.Enabled = True
  177. End Sub
  178.  
  179.  
  180. Private Sub Winout_DataArrival(ByVal bytesTotal As Long)
  181. timeOut.Enabled = False
  182. Winout.GetData Response
  183. timeOut.Enabled = True
  184. End Sub
  185.